<?php
class Admin_service extends Contact_Controller{
	function __construct(){
		parent :: __construct();
		$this->load->model('Service_m');
		$this->_data['sidebar']="service";
		
		
	}
	
	function index(){
		$this->service_information();	
	}
	
	//--view service information--//
	function service_information(){
		is_admin();
		$this->_data['page_title'] = "Service information";
		//add new service content if service content is null
		$query_service_content = $this->Service_m->check_exist_record(); 
		if($query_service_content){ //if exist content on service, load form edit
			$contentRow = $query_service_content->row();
			$this->edit_service_information($contentRow->id);
		}else{//if not exist content on service, load form add
			$this->add_service_information();	
			
		}   
		
		
	}
	
	function add_service_information(){
			$config = array(
							array("field" => "content", 
								  "label" => lang("content"),
								  "rules" => "required|xss_clean|trim"
								 )
							
				       		);
			$this->form_validation->set_rules($config);
			
			if($this->input->post("add_service_content")){
				if($this->form_validation->run()=== false){
					$this->display_admin('admin/service/add_service_information');	
				}else{
					$data = array("id"=>1, "content"=>$this->input->post("content"));
					if($this->Service_m->add_service_content($data)){
						$this->session->set_flashdata('error', lang('add') ." ". lang('success'));
						redirect('admin_service');
					}	
				}		
			}else{
				$this->display_admin('admin/service/add_service_information');		
			}
	}
	
	function edit_service_information($id =  null){
			
			$config = array(
							array("field" => "content", 
								  "label" => lang("content"),
								  "rules" => "required|xss_clean|trim"
								 )
							
				       		);
			$this->form_validation->set_rules($config);
			$query_service_content = $this->Service_m->load_service_content($id);
			if($query_service_content === FALSE){
				redirect("Admin_service");
			}
			$this->_data['service_content'] = $query_service_content->row();
			if($this->input->post("edit_service_content")){
				if($this->form_validation->run()=== false){
					$this->display_admin('admin/service/update_service_information');	
				}else{
					$data = array("content" => $this->input->post("content"));
					if($this->Service_m->edit_service_content($id, $data)){
						$this->session->set_flashdata('error', lang('edit_profile') ." ". lang('success'));
						redirect('admin_service');
					}	
				}		
			}else{
				$this->display_admin('admin/service/update_service_information');		
			}
		
	}
	

}

	